using System;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
    public class ConfigurationSettingComparerBI : IComparer<ConfigurationSettingInfo>
    {
        private string _sortExpression;
        public string SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

		private string _sortDirection;
        public string SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }

        public ConfigurationSettingComparerBI(string sortExpression)
        {
            int iSplitPos = sortExpression.IndexOf(" ");
            SortExpression = (iSplitPos > 0) ? sortExpression.Substring(0, iSplitPos) : sortExpression;
            SortDirection = (iSplitPos > 0) ? sortExpression.Substring(iSplitPos + 1).ToUpper() : "ASC";
        }

        public ConfigurationSettingComparerBI(string sortExpression, string sortDirection)
        {
            this.SortExpression = sortExpression;
            this.SortDirection = sortDirection;
        }

        int IComparer<ConfigurationSettingInfo>.Compare(ConfigurationSettingInfo x, ConfigurationSettingInfo y)
        {
            ConfigurationSettingInfo oX = (SortDirection == "ASC") ? x : y;
            ConfigurationSettingInfo oY = (SortDirection == "ASC") ? y : x;

            switch (SortExpression)
            {				
				case "ConfigurationId":
					return oX.ConfigurationId.CompareTo(oY.ConfigurationId);				
				case "SettingId":
					return oX.SettingId.CompareTo(oY.SettingId);				
				case "Active":
					return oX.Active.CompareTo(oY.Active);				
				case "PermissionFlag":
					return oX.PermissionFlag.CompareTo(oY.PermissionFlag);				
				case "Value":
					return oX.Value.CompareTo(oY.Value);				
				case "Pattern":
					return oX.Pattern.CompareTo(oY.Pattern);				
				case "Replacement":
					return oX.Replacement.CompareTo(oY.Replacement);
                    // Custom BI
                case "Setting":
                    return oX.Setting.CompareTo(oY.Setting);
                case "Category":
                    return oX.Category.CompareTo(oY.Category);
                case "SubCategory":
                    return oX.Subcategory.CompareTo(oY.Subcategory);
                default:
                    return 0;
            }
        }
    }
}
